/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.Controller;

import admin_gui.*;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author WEN
 */
public class ManageController {

    private JPanel mainPanel;

    public ManageController(AdminGUI aThis, Admin_Manage amanage,
            JPanel MainPanel) {
      //  System.out.println("in controller1");
        mainPanel = MainPanel;
    }
    public void manageOperation(boolean add,boolean search,
        boolean[]manageItem,JPanel mainPanel) {
        if(add==false&&search==false){
            JOptionPane.showMessageDialog(null,"Please choose one operation",
               "Error", JOptionPane.ERROR_MESSAGE);
        }
        else if(manageItem[0] == true)
        {
            JOptionPane.showMessageDialog(null,"Please choose one item to manage",
               "Error", JOptionPane.ERROR_MESSAGE);
        }
        else if(add == true)
        {
            for(int i=1;i<manageItem.length;i++){
                if(manageItem[i]==true){
                    showManageItemPanel(i, mainPanel);
                }
            }
        } else if (search == true) {
            for (int i = 1; i < manageItem.length; i++) {
                if (manageItem[i] == true) {
                    showSearchItemPanel(i, mainPanel);
                }
            }
        }
    }
    public void showManageItemPanel(int i,JPanel panel){
        switch(i){
            case 1: Admin_AddItem addItemPane = new Admin_AddItem();
                    addItemPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(addItemPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 2: Admin_AddPromo addPromoPane = new Admin_AddPromo();
                    addPromoPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(addPromoPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 3: Admin_AddClerk addClerkPane = new Admin_AddClerk(mainPanel);
                    addClerkPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(addClerkPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 4: Admin_AddStore addStorePane = new Admin_AddStore(mainPanel);
                    addStorePane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(addStorePane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 5: JOptionPane.showMessageDialog(null,"Order can not be added",
                    "Error", JOptionPane.ERROR_MESSAGE);
                     break;
        }
    }
    public void showSearchItemPanel(int i,JPanel panel){
        switch(i){
            case 1: Admin_SearchItem searchItemPane = new Admin_SearchItem(mainPanel);
                    searchItemPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(searchItemPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 2: Admin_SearchPromo searchPromoPane = new Admin_SearchPromo(mainPanel);
                    searchPromoPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(searchPromoPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 3: Admin_SearchClerk searchClerkPane = new Admin_SearchClerk(mainPanel);
                    searchClerkPane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(searchClerkPane);
                    panel.validate();
                    panel.repaint();
                    break;
            case 4: Admin_SearchStore searchStorePane = new Admin_SearchStore(mainPanel);
                    searchStorePane.setBounds(1,1, 762, 613);
                    panel.removeAll();
                    panel.add(searchStorePane);
                    panel.validate();
                    panel.repaint();
                    break;

            case 5:
                Admin_SearchOrder searchOrderPane = new Admin_SearchOrder(
                        mainPanel);
                searchOrderPane.setBounds(1, 1, 762, 613);
                panel.removeAll();
                panel.add(searchOrderPane);
                panel.validate();
                panel.repaint();
                break;
        }
    }
}
